<?php
class website extends table
{
	protected $_name	= 'my_website';
	protected $fields	= array('wid',	'cid',	'domain',	'host',	'username',	'password',	'dbname',	'prefix',	'charset',);
	protected $_primary = 'wid';
	
	public static function getConfig($domain)
	{
		$path = self::getConfPath($domain);
		is_file($path) && include $path;
		$attr['tempdir']	= 'data/'.$domain.'/template/';
		return isset($attr) ? $attr : false;
	}

	public static function getConfPath($domain)
	{
		return realpath(ROOT . '/data').'/'.$domain.'/config.php';
	}

	public static function setConfig($arg,$domain)
	{
		ob_start();
		$attr = array(
			'title'			=> $arg['sitename'],
			'url'			=> $arg['newsurl'],
            'arcdir'		=> (stripslashes($arg['arcdir'])),
            'tempdir'		=> 'data/'.$domain.'/template/',
			'fileurl'		=> $arg['fileurl'],
			'email'			=> $arg['email'],
			'keywords'		=> $arg['sitekey'],
			'description'	=> $arg['siteintro'],
			'indextype'		=> $arg['indextype'],
            'indextemp'		=> $arg['indextemp'],
		);
		var_export($attr);
		$attr = ob_get_contents();
		ob_end_clean();

		$path = realpath(ROOT . '/data').'/'.$domain;
		is_dir($path) || mdir($path);
		$fp	= fopen($path . '/config.php','w');
		fwrite($fp,"<?php\n\$attr = ".$attr.';');
		fclose($fp);
	}
}